package db;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import model.Service;

public class DBOffer extends DBService implements IFOffer
{
	private Connection con;

	public DBOffer()
	{
		con = DBConnection.getInstance().getDBcon();
	}

	@Override
	public Service searchOfferByID(int offerID) throws SQLException
	{
		ResultSet results;
		Service service = new Service();

		String query = "SELECT o.offer_request_id, o.offer_service_id  FROM offer AS o WHERE o.offer_service_id = ?";

		if(DBConnection.doDebug())
			DBConnection.printDebug("getOne", query);

		try
		{
			PreparedStatement ps = con.prepareStatement(query);

			ps.setInt(1, offerID);

			results = ps.executeQuery();
			if(results.next())
			{
				service = new Service();
				service.setServiceID(results.getInt("offer_service_id"));

			}

			ps.close();
		}
		catch(Exception e)
		{
			if(DBConnection.doDebug())
			{
				System.out.println("error query exception - getOne - SELECT: " + e);
				e.printStackTrace();
			}
		}

		return service;
	}
}